import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexExample1 {
    public static void main(String[] args) {
        String match_str = "My name is XXX, " +
                "I am 18 years old, " +
                "my telephone number is 17826150236, " +
                "my email is 307157473@qq.com .";
        findAllNumber(match_str);
        findAllPhone(match_str);
    }

    private static void findAllNumber(String match_str) {
        String regex = "\\d+"; // 第一个"\"表转义 ，"\d"表示匹配数字 等效于 [0-9]，+表示 一次或多次匹配前面的字符或子表达式。
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(match_str);
        int i = 0;
        while (matcher.find()) {
            i++;
            System.out.println("匹配的第" + i + "个数字:" + matcher.group());
        }
    }
    private static void findAllPhone(String match_str) {
        String regex = "[1][3,4,5,7,8][0-9]{9}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(match_str);
        int i = 0;
        while (matcher.find()) {
            i++;
            System.out.println("匹配的第" + i + "个号码:" + matcher.group());
        }
    }
}
